package com.xiong.miaosha.rabbitmq;

import com.xiong.miaosha.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wardseptember
 * @create 2020-03-22 10:39
 */
@Service
public class MQSender {
    private static Logger logger = LoggerFactory.getLogger(MQReceiver.class);

    @Autowired
    AmqpTemplate amqpTemplate;

    public void sender(Object message) {
        String msg = RedisService.beanToString(message);
        logger.info("sender message:" + msg);
        amqpTemplate.convertAndSend(MQConfig.QUEUE, message);
    }

    public void sendMiaoshaMessage(MiaoshaMessage miaoshaMessage) {
        String msg = RedisService.beanToString(miaoshaMessage);
        logger.info("sender message:" + msg);
        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE, msg);
    }
}
